<%@ Page language="vb" CodeFile="amountFix.aspx.vb" Inherits="amountFix_aspx_vb" %>

<%
    If Request.QueryString("do") = "authorizedAmount" Then 
        dbOpen()
        RecSet = Conn.Execute("Select c.claimID, ((Select IsNull(Sum(cm.authorisedCostPerHour*cm.authorisedNumberOfHours),0) From tblClaimMoment cm Where cm.claimID = c.claimID)+(Select IsNull(Sum(cp.authorisedCostPerPart*cp.authorisedNumberOfParts),0) From tblClaimPart cp Where cp.claimID = c.claimID)+(Select IsNull(Sum(cs.authorisedCostPerService*cs.authorisedNumberOfService),0) From tblClaimService cs Where cs.claimID = c.claimID)+c.authorizedConsumptionMaterialAmount) As authorizedAmount From tblClaim c Order By claimID")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                claimID = RecSet.Fields("claimID").Value
                authorizedAmount = RecSet.Fields("authorizedAmount").Value
                If IsDBNull(authorizedAmount) = true Then 
                    authorizedAmount = 0
                End IF
                authorizedAmount = FormatNumber(CDbl(authorizedAmount), 2)
                authorizedAmount = CDbl(authorizedAmount)
                authorizedAmount = Replace(CStr(authorizedAmount), ",", ".")
                Response.Write("Update tblClaim Set authorizedAmount = " & authorizedAmount & " Where ClaimID = " & claimID & "<br>")
                Conn.Execute("Update tblClaim Set authorizedAmount = " & authorizedAmount & " Where ClaimID = " & claimID & "")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
    ElseIf Request.QueryString("do") = "requestedAmount" Then 
        dbOpen()
        RecSet = Conn.Execute("Select c.claimID, ((Select IsNull(Sum(cm.costPerHour*cm.numberOfHours),0) From tblClaimMoment cm Where cm.claimID = c.claimID)+(Select IsNull(Sum(cp.costPerPart*cp.numberOfParts),0) From tblClaimPart cp Where cp.claimID = c.claimID)+(Select IsNull(Sum(cs.costPerService*cs.numberOfService),0) From tblClaimService cs Where cs.claimID = c.claimID)+c.consumptionMaterialAmount) As requestedAmount From tblClaim c Order By claimID")
        If Not RecSet.EOF Then 
            Do Until RecSet.EOF
                claimID = RecSet.Fields("claimID").Value
                requestedAmount = RecSet.Fields("requestedAmount").Value
                If IsDBNull(requestedAmount) = true Then 
                    requestedAmount = 0
                End IF
                requestedAmount = FormatNumber(CDbl(requestedAmount), 2)
                requestedAmount = CDbl(requestedAmount)
                requestedAmount = Replace(CStr(requestedAmount), ",", ".")
                Response.Write("Update tblClaim Set requestedAmount = " & requestedAmount & " Where ClaimID = " & claimID & "<br>")
                Conn.Execute("Update tblClaim Set requestedAmount = " & requestedAmount & " Where ClaimID = " & claimID & "")
                RecSet.MoveNext()
            Loop
        End IF
        RecSet.Close()
        RecSet = Nothing
        dbClose()
    End IF
%>
